package com.mls.fivedistrict.controller.portal;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mls.fivedistrict.common.PageFilter;
import com.mls.fivedistrict.common.RequestHolder;
import com.mls.fivedistrict.common.ServiceResponse;
import com.mls.fivedistrict.pojo.IntegralPrice;
import com.mls.fivedistrict.pojo.ShippingAddress;
import com.mls.fivedistrict.server.IntegralPriceService;
import com.mls.fivedistrict.server.ShippingAddressService;
import com.mls.fivedistrict.util.validator.BeanValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Five Team
 * @since 2018-07-02
 */
@RestController("portalIntegralPriceController")
@RequestMapping("/api/app")
public class IntegralPriceController {
    @Autowired
    private IntegralPriceService integralPriceService;

    /**
     * 获取积分价格列表
     *
     * @return
     */
    @GetMapping("/v1/integralPrices")
    public ServiceResponse getIntegralPriceList() {
        PageFilter pageFilter = RequestHolder.getPageFilter();
        PageHelper.startPage(pageFilter.getPageNum(), pageFilter.getPageSize());
        List<IntegralPrice> integralPriceList = integralPriceService.selectList(pageFilter.getWrapper());
        PageInfo<IntegralPrice> pageInfo = new PageInfo<>(integralPriceList, 5);
        return ServiceResponse.createSuccessResponse(pageInfo);
    }

    /**
     * 写入积分价格
     *
     * @param integralPrice
     * @return
     */
    @PostMapping("/v1/integralPrice")
    public ServiceResponse insert(@RequestBody IntegralPrice integralPrice) {
        BeanValidator.check(integralPrice);
        boolean insert = integralPriceService.insert(integralPrice);
        if (!insert) {
            return ServiceResponse.createErrorResponse("插入失败");
        }
        return ServiceResponse.createSuccessResponse("插入成功");
    }
}

